package Servlet;

import Bean.Ticket;
import Service.TicketService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张
 * Date: 2025-03-13
 * Time: 21:44
 */
@WebServlet("/RevokeQuitServlet")
public class RevokeQuitServlet extends HttpServlet {
    private TicketService ticketService = new TicketService();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf8");
        String orderId = req.getParameter("flightId");
//        System.out.println("获取到的订单编号为 : " + orderId);
        String userId = (String) req.getSession().getAttribute("LoginUserId");
        Ticket ticket = new Ticket();
        ticket.setStatus(Ticket.TicketStatus.已预订);
        ticket.setFlightId(orderId);
        ticket.setUserId(userId);
        int ret = ticketService.updateStatus(ticket);
        if(ret == 0) {
            req.setAttribute("status", "error");
            req.setAttribute("message", "操作失败");
            req.setAttribute("redirectUrl", "QuitListByUserIdServlet?pageNo=1");
            req.setAttribute("waitSeconds", 2);
            req.getRequestDispatcher("skip.jsp").forward(req,resp);
        }
        req.getRequestDispatcher("QuitListByUserIdServlet?pageNo=1").forward(req,resp);
    }
}
